package main

import "fmt"

//#link: https://leetcode-cn.com/problems/peak-index-in-a-mountain-array/
func main() {
	arr := []int{0, 2, 1, 0}
	fmt.Println(peakIndexInMountainArray(arr))
}

func peakIndexInMountainArray(arr []int) int {
	//for i:=1;i<len(arr);i++{
	//	if arr[i]<arr[i-1]{
	//		return i-1
	//	}
	//}
	//return 0
	left, right := 1, len(arr)-2
	ans := 0
	for left <= right {
		mid := (left + right) >> 1
		if arr[mid] > arr[mid+1] {
			ans = mid
			right = mid - 1
		} else {
			left = mid + 1
		}
	}
	return ans

}
